package pe.gob.osinergmin.interfase_siaf.dac.certificacion.dao.impl;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import pe.gob.osinergmin.interfase_siaf.dac.certificacion.dao.CertDetDao;
import pe.gob.osinergmin.interfase_siaf.dac.domain.interfase.CertDet;

@Repository("certDetDao")
public class CertDetDaoImpl implements CertDetDao {

	   private final Log logger = LogFactory.getLog(getClass());
	 	
		
		private NamedParameterJdbcTemplate jdbcParameterTemplateInterfase;	
		//private JdbcTemplate jdbcTemplateInterfase;		
		
		
		@Autowired
		public void SetDataSource(DataSource dataSourceInterfase){
		//	this.jdbcTemplateInterfase = new JdbcTemplate(dataSourceInterfase);
			this.jdbcParameterTemplateInterfase = new NamedParameterJdbcTemplate(dataSourceInterfase);		
		}
		
		
		/**DECLARACION DE SQL**/	
		private static final String SQL_SELECT_SECUENCIAL="SELECT COUNT(secuencial) FROM CERT_DET "
				+ " WHERE secuencial=:secuencial";
		
		
		/**IMPLEMENTACION DE METODOS*/
		
		@Override
		public int verificarSecuencialDet(CertDet d) throws Exception {
			logger.info("ingresando a verificar el secuencial cert_det"); 
			SqlParameterSource parameters = new BeanPropertySqlParameterSource(d);	
		    return this.jdbcParameterTemplateInterfase.queryForInt(SQL_SELECT_SECUENCIAL, parameters);	
		}
		
}
